﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Granite.Modeling;
using Toon.Models.Catalogs;
using System.Xml.Linq;

namespace Toon.Models.Characters
{
    public class Possession : ChangeTrackingModelBase
    {
        public Possession(PossessionDefinition definition)
        {
            Name = definition.Name;
            Type = definition.Type;
            Notes = definition.Notes ?? "";
        }

        public Possession(string name, PossessionType type, string notes = "")
        {
            Name = name;
            Type = type;
            Notes = notes ?? "";
        }

        public string Name
        {
            get { return Get<string>("Name"); }
			set { Set(value, "Name"); }
        }

        public PossessionType Type
        {
            get { return Get<PossessionType>("Type"); }
			set { Set(value, "Type"); }
        }

        public string Notes
        {
            get { return Get<string>("Notes"); }
			set { Set(value, "Notes"); }
        }

        internal XElement ToXml()
        {
            return new XElement("Possession",
                new XAttribute("Name", Name),
                new XAttribute("Type", Type),
                new XAttribute("Notes", Notes));
        }

        internal Possession(XElement source)
        {
            Name = source.Attribute("Name").Value;
            Type = (PossessionType)Enum.Parse(typeof(PossessionType), source.Attribute("Type").Value, false);
            Notes = source.Attribute("Notes").Value;
        }

        public override string ToString()
        {
            return string.Format("{0}{1}", Name, Type == PossessionType.Normal ? "" : "*");
        }
    }
}

